<template>
  <div class="app-container" v-loading="loading.getPageList">
    <div>
      <el-button type="primary" size="small" @click="$refs.createForm.show()"
        >新增</el-button
      >
      <el-button type="primary" size="small" @click="getPageList"
        >刷新</el-button
      >
    </div>
    <br />

    <el-table :data="tableData" border style="width: 100%">
      <el-table-column type="index" label="序号" width="60"> </el-table-column>
      <el-table-column prop="name" label="名称" width="220"> </el-table-column>
      <el-table-column prop="activeVersion" label="版本" width="60">
      </el-table-column>
      <el-table-column prop="description" label="描述"> </el-table-column>
      <el-table-column
        prop="modifiedTime"
        label="更新日期"
        :formatter="dateFormat"
        width="150"
      >
      </el-table-column>
      <el-table-column
        prop="creationTime"
        label="创建日期"
        :formatter="dateFormat"
        width="150"
      >
      </el-table-column>
      <el-table-column> </el-table-column>
      <el-table-column fixed="right" label="操作" width="240">
        <template slot-scope="scope">
          <el-button
            @click="$refs.updateVersionForm.show(scope.row)"
            type="text"
            size="small"
            >版本切换</el-button
          >

          <el-button
            @click="
              $router.push({
                path: '/workflowDesign/simulation',
                query: {
                  id: scope.row.id,
                  versionId: scope.row.activeVersion,
                  name: scope.row.name,
                },
              })
            "
            type="text"
            size="small"
            >模拟</el-button
          >
          <el-button
            type="text"
            size="small"
            @click="
              $router.push({
                path: '/editworkflow/edit',
                query: {
                  id: scope.row.id,
                  versionId: scope.row.activeVersion,
                  name: scope.row.name,
                  des: scope.row.description,
                },
              })
            "
            >编辑</el-button
          >
          <el-button
            type="text"
            size="small"
            @click="
              $refs.viewWorkflowForm.show({
                id: scope.row.id,
                version: scope.row.activeVersion,
                name: scope.row.name,
              })
            "
            >查看</el-button
          >
          <el-button @click="remove(scope.row.id)" type="text" size="small"
            >删除</el-button
          >
        </template>
      </el-table-column>
    </el-table>
    <br />
    <el-pagination
      background
      layout="sizes,prev, pager, next"
      :total="page.total"
      :page-size="page.maxResultCount"
      :current-page="page.currentPage"
      @current-change="(current) => paginationChange(null, current)"
      @size-change="(size) => paginationChange(size)"
    >
    </el-pagination>

    <createForm
      ref="createForm"
      @ok-click="
        (wf) =>
          $router.push({
            path: '/editworkflow/edit',
            query: {
              id: wf.id,
              versionId: wf.activeVersion,
              name: wf.name,
              des: wf.description,
            },
          })
      "
    ></createForm>
    <!-- 版本切换  -->
    <updateVersionForm ref="updateVersionForm" @ok-click="getPageList()">
    </updateVersionForm>
    <!-- 流程预览 -->
    <viewWorkflowForm ref="viewWorkflowForm"></viewWorkflowForm>

  </div>
</template>

<script>
import createForm from "./createForm";
import updateVersionForm from "./updateVersionForm";
import TableIndex from "@/layout/mixin/TableIndex";
import viewWorkflowForm from "./viewWorkflowForm";
import simulation from "./../workFlowSimulation/index"
export default {
  components: { createForm, updateVersionForm, viewWorkflowForm,simulation },
  mixins: [TableIndex],
  methods: {
    handleClick(row) {
      console.log(row);
    },
  },

  data() {
    return {
      moduleName: "workflow",
      drawerSimulation:{
        show:false,
        id: '',
        versionId: 0,
        name:'',
      }
    };
  },
  mounted() {
    this.getPageList();
  },
  methods: {
    getPageList() {
      this.loading.getPageList = true;
      this.$store
        .dispatch("workflow/getAllWorkflows", this.page)
        .then((res) => {
          
          this.tableData = res.items;
          this.page.total = res.total;
          this.loading.getPageList = false;
        });
    },
  },
};
</script>

<style></style>
